package  com.dg11185.nearshop.view.xlistview;

/**
 * @file XListViewHeader.java
 * @create Apr 18, 2012 5:22:27 PM
 * @author Maxwin
 * @description XListView's header
 */

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.android.nearshop.R;

public class XListViewHeader extends IXListViewHeader {

    private ImageView mCartonImageView;

    private ProgressBar mProgressBar;

    private TextView mHintTextView;

    private AnimationDrawable anim;


    public XListViewHeader(Context context) {
        super(context,R.layout.third_xlistview_header);
        initView(context);
    }

    /**
     * @param context
     * @param attrs
     */
    public XListViewHeader(Context context, AttributeSet attrs) {
        super(context, attrs,R.layout.third_xlistview_header);
        initView(context);
    }

    private void initView(Context context) {

        mCartonImageView = (ImageView) findViewById(R.id.xlistview_header_carton);
        mHintTextView = (TextView) findViewById(R.id.xlistview_header_hint_textview);
        mProgressBar = (ProgressBar) findViewById(R.id.xlistview_header_progressbar);

        anim = (AnimationDrawable) mCartonImageView.getBackground();

    }

    public void setState(int state) {
        if (state == mState)
            return;
        
        if (state == STATE_REFRESHING) {  
            mProgressBar.setVisibility(View.VISIBLE);
        } else {
            mProgressBar.setVisibility(View.INVISIBLE);
        }
        
        switch (state) {
        case STATE_NORMAL:
            mHintTextView.setText(R.string.xlistview_header_hint_normal);
            break;
        case STATE_READY:
            if (mState != STATE_READY) {
                mHintTextView.setText(R.string.xlistview_header_hint_ready);
            }
            break;
        case STATE_REFRESHING:
            anim.start();
            mHintTextView.setText(R.string.xlistview_header_hint_refresh);
            break;
        case STATE_REFRESH_OVER:
            anim.stop();
            break;
        default:
        }

        mState = state;
    }

}
